package com.etc;


import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class UserReduce extends Reducer<Text,User,User, NullWritable> {
    @Override
    protected void reduce(Text key, Iterable<User> values, Context context) throws IOException, InterruptedException {
        //定义一个list集合
        List<User> list = new ArrayList<User>();
        String Coding = null;
        //如果logo跟1匹配
        for(User user : values) {
            if ("1".equals(user.getLogo())) {
                list.add(new User(user.getCoding(),user.getUserId(),user.getName(),user.getAge(),user.getStar(),user.getLogo()));
            }else {
                Coding = user.getCoding();
            }
        }

        for(User user : list){
            user.setCoding(Coding);
            context.write(user,NullWritable.get());
        }
    }
}
